import { AlbumPage, AlbumPageSearchParams } from '@/api/albumPage/model';
import request from '@/utils/request';
import { ApiResult, PageResult } from '@/api';

/**
 * 添加相册
 * @param data
 */
export async function addAlbumPage(data: AlbumPage) {
  const res = await request.post<ApiResult<unknown>>('/albumPage', data);
  if (res.data.code === 0) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 更新相册
 * @param data
 */
export async function updateAlbumPage(data: AlbumPage) {
  const res = await request.put<ApiResult<unknown>>('/albumPage', data);
  if (res.data.code === 0) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取相册列表
 * @param data
 */
export async function getAlbumPageList(data: AlbumPageSearchParams) {
  const res = await request.get<ApiResult<PageResult<AlbumPage>>>(
    '/albumPage',
    {
      params: data
    }
  );
  if (res.data.code === 0) {
    const pageData = {
      list: res.data.data?.records,
      count: res.data.data?.total
    };
    return pageData;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除内页
 * @param id
 * @param status
 */
export async function deleteAlbumPage(id?: string) {
  const res = await request.delete<ApiResult<unknown>>('/albumPage/' + id);
  if (res.data.code === 0) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
